home *** CD-ROM | disk | FTP | other *** search
/ Garden Fax: Fruits, Vegetables & Herbs / Garden Fax - Fruits, Vegetables & Herbs (1991)(CDTV Publishing)[!].iso / system / basicdemos / convertfd < prev    next >
Text File  |  1978-01-06  |  5KB  |  186 lines

  1. 'Program: ConvertFd - created Aug 9, 1985
  2. 'This program converts .fd files, like 'graphics_lib.fd' to
  3. ' .bmap format files, like 'graphics.bmap', so BASIC
  4. ' programs can access libraries of machine language routines
  5. ' by name via the LIBRARY statement.
  6. '
  7. ' Modified  01/86 by Carolyn Scheppner  CBM
  8. '   Prepends an x to all function names which
  9. '    conflict with AmigaBasic keywords.
  10. '    See data statements at end of program for
  11. '    known conflicts.  To call these functions,
  12. '    prepend an x  (example  xRead).
  13. '   Saves the .bmap file in current or specified
  14. '    directory (previously saved in LIBS:).
  15. '    For your program to access the .bmap via
  16. '    LIBRARY, it must be in the current dir
  17. '    or the LIBS: dir.
  18. '   The name of a .bmap file must match its
  19. '    library's name.  The libraryname is the
  20. '    part of the .fd file name before the _.
  21. '    (example   dos.bmap from dos_lib.fd)
  22.  
  23.  
  24.   DEFINT a-Z    'by default, all variables ares integer
  25.  
  26.   REM ******** for conflicting tokens ********
  27.   READ cnt       'count of conflicting tokens
  28.   DIM con$(cnt)
  29.   FOR k = 0 TO cnt-1: READ con$(k): NEXT
  30.   REM ****************************************
  31.  
  32.   INPUT "Enter name of .fd file to read > ",fdFilename$
  33.   OPEN fdFilename$ FOR INPUT AS #1
  34.   INPUT "Enter name of .bmap file to produce > ",bmapFilename$
  35.   OPEN bmapFilename$ FOR OUTPUT AS #2
  36.   WHILE NOT EOF(1)
  37.     GetLine
  38.     IF char$ = "#" THEN
  39.       'lines which begin with "#" are command lines
  40.       GOSUB GotCommand
  41.     ELSEIF char$ = "*" THEN
  42.       'lines which begin with "*" are comment lines
  43.     ELSEIF char$ = CHR$(10) OR char$ = CHR$(13) THEN
  44.       'blank line
  45.     ELSE
  46.       'all other lines define a function in the library
  47.       GOSUB GotFunction
  48.     END IF
  49.   WEND
  50.   CLOSE
  51.   END
  52.  
  53. GotCommand:
  54.   GetChar  'skip 1st "#"
  55.   GetChar  'skip 2nd "#"
  56.   GetToken
  57.   IF token$ = "bias" THEN
  58.     GetNum
  59.     offset = -num
  60.   END IF
  61.  ram: RETURN
  62.  
  63. GotFunction:
  64.   GetToken  'token$=function's name
  65.  
  66.   REM **** prepend conflicting tokens with 'x' ****
  67.   k$ = token$
  68.   FOR k = 0 TO cnt-1
  69.      IF k$ = con$(k) THEN token$ = "x" + token$ 
  70.   NEXT   
  71.   REM **********************************************
  72.  
  73.   funcOffset=offset
  74.   offset=offset-6
  75.   parms$=""
  76.   SkipTill "(": IF char$="" THEN BadFileFormat
  77.   SkipTill ")": IF char$="" THEN BadFileFormat
  78.   GetChar
  79.   IF char$<>"" THEN
  80.     SkipTill "(": IF char$="" THEN BadFileFormat
  81.     WHILE char$ <> ")"
  82.       GetChar 'skip ( or , or /
  83.       IF char$<>")" THEN
  84.         GOSUB GetRegister
  85.         IF register=0 THEN BadFileFormat
  86.         IF register=-1 THEN
  87.           PRINT "Warning: Function ";token$;" not included because it"
  88.           PRINT " needs a parameter passed in a register BASIC cannot"
  89.           PRINT " conform to."
  90.           PRINT
  91.           RETURN
  92.         END IF
  93.         parms$ = parms$+CHR$(register)
  94.          'tells BASIC which register to put this parm into
  95.       END IF
  96.     WEND
  97.   END IF
  98.   AddEntry token$,funcOffset
  99.   PRINT #2,parms$;   'tells BASIC what registers to pass parms in
  100.   PRINT #2,CHR$(0);  'marks end of function entry
  101.   RETURN
  102.  
  103. BadFileFormat:
  104.   PRINT "Error: ";fdFilename$;" has a format error"
  105.   PRINT "In line:";lineNum;":";buf$
  106.   PRINT "In column:";column
  107.   CLOSE
  108.   STOP
  109.   
  110.  
  111. 'map {d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4} to {1,..,13}
  112. GetRegister:
  113.   uchar$=UCASE$(char$)
  114.   IF uchar$="D" THEN
  115.     register=1
  116.   ELSEIF uchar$="A" THEN
  117.     register = 9
  118.   ELSE
  119.     register=0  'error
  120.     RETURN
  121.   END IF
  122.   GetChar  'skip a or d
  123.   i=ASC(char$)-48
  124.   IF i<0 OR i>7 THEN register=0: RETURN  'error
  125.   GetChar  'skip digit
  126.   register=register+i
  127.   IF register>13 THEN register=-1  'error
  128.   RETURN
  129.  
  130. SUB AddEntry(nam$, liboffset%) STATIC
  131.   highByte = PEEK(VARPTR(liboffset%))
  132.   lowByte = PEEK(VARPTR(liboffset%)+1)
  133.   PRINT #2,nam$; CHR$(0); CHR$(highByte); CHR$(lowByte);
  134.   END SUB
  135.  
  136. SUB GetLine STATIC
  137.   SHARED buf$,column,lineNum
  138.   LINE INPUT #1,buf$
  139.   column = 0
  140.   GetChar
  141.   lineNum = lineNum+1
  142.   END SUB
  143.  
  144. SUB GetNum STATIC
  145.   SHARED num,token$
  146.   GetToken
  147.   num = VAL(token$)
  148.   END SUB
  149.  
  150. SUB GetToken STATIC
  151.   SHARED buf$,char$,token$
  152.   SkipWhiteSpace
  153.   token$=""
  154.   uchar$=UCASE$(char$)
  155.   WHILE ((uchar$>="A") AND (uchar$<="Z")) OR ((uchar$>="0") AND (uchar$<="9")) OR (uchar$="-")
  156.     token$=token$+char$
  157.     GetChar
  158.     uchar$ = UCASE$(char$)
  159.   WEND
  160.   END SUB
  161.  
  162. SUB SkipTill(stopChar$) STATIC
  163.   SHARED char$
  164.   WHILE (char$ <> stopChar$) AND (char$ <> "")
  165.     GetChar
  166.   WEND
  167.   END SUB
  168.  
  169. SUB SkipWhiteSpace STATIC
  170.   SHARED char$
  171.   WHILE (char$=" ") OR (char$=CHR$(9))
  172.     GetChar
  173.   WEND
  174.   END SUB
  175.  
  176. SUB GetChar STATIC
  177.   SHARED column,char$,buf$
  178.   column = column + 1
  179.   char$ = MID$(buf$,column,1)
  180.   END SUB
  181.        
  182. REM **** conficting token count and tokens ****                
  183. DATA 11                
  184. DATA abs, Close, Exit, Input, Open, Output
  185. DATA Read, tan, Translate, Wait, Write
  186.